#pragma once
#include <functional>
#include <map>

#include "Singleton.h"

class HttpConnection;

typedef std::function<void(std::shared_ptr<HttpConnection>)> HttpHandler;

class LogicSystem : public Singleton<LogicSystem> {
  friend class Singleton<LogicSystem>;

 public:
  ~LogicSystem();
  bool HandleGet(std::string path,std::shared_ptr<HttpConnection> cn);  // 处理get请求
  bool HandlePost(std::string path,std::shared_ptr<HttpConnection> cn);  // 处理get请求
  void RegGet(std::string url, HttpHandler handler);   // 注册get请求
  void RegPost(std::string url, HttpHandler handler);  // 注册post请求

 private:
  LogicSystem();
  // 键值对 key-value  key为路由，value为回调函数
  std::map<std::string, HttpHandler> _post_handlers;  // post 请求的回调函数map
  std::map<std::string, HttpHandler> _get_handlers;  // get 请求的回调函数map
};
